// ==========================================================================
// GFast自动生成dao internal操作代码。
// 生成日期：2024-11-11 20:52:34
// 生成路径: internal/app/system/dao/internal/users.go
// 生成人：王中阳
// desc:用户
// company:云南奇讯科技有限公司
// ==========================================================================

package internal

import (
	"context"

	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"
)

// UsersDao is the manager for logic model data accessing and custom defined data operations functions management.
type UsersDao struct {
	table   string       // Table is the underlying table name of the DAO.
	group   string       // Group is the database configuration group name of current DAO.
	columns UsersColumns // Columns is the short type for Columns, which contains all the column names of Table for convenient usage.
}

// UsersColumns defines and stores column names for table users.
type UsersColumns struct {
	Id                string //
	Username          string // 用户名
	Phone             string // 手机号
	UserType          string // 是否注册跑手，0表示否，1表示是
	Openid            string // 微信授权登录获取的唯一标识
	Unionid           string // 微信多平台唯一标识，用于在不同微信平台间识别同一用户
	Gender            string // 性别，1表示男，2表示女，0表示未知
	Country           string // 国家
	Province          string // 省份
	City              string // 城市
	AvatarUrl         string // 用户头像的URL地址
	IsBan             string // 是否被封禁，0表示未被封禁，1表示被封禁
	Score             string // 用户积分
	SchoolId          string // 学校ID
	IsFirst           string // 是否首次登录
	PayQrCodePath     string // 支付二维码的存储路径
	Wallet            string // 钱包余额
	Diamonds          string // 抽奖总金币
	Balance           string // 钱包余额
	TotalLotteryCount string // 抽奖总次数
	CreatedAt         string // 创建时间
	UpdatedAt         string // 更新时间
	DeletedAt         string // 删除时间
}

var usersColumns = UsersColumns{
	Id:                "id",
	Username:          "username",
	Phone:             "phone",
	UserType:          "user_type",
	Openid:            "openid",
	Unionid:           "unionid",
	Gender:            "gender",
	Country:           "country",
	Province:          "province",
	City:              "city",
	AvatarUrl:         "avatar_url",
	IsBan:             "is_ban",
	Score:             "score",
	SchoolId:          "school_id",
	IsFirst:           "is_first",
	PayQrCodePath:     "pay_qr_code_path",
	Wallet:            "wallet",
	Diamonds:          "diamonds",
	Balance:           "balance",
	TotalLotteryCount: "total_lottery_count",
	CreatedAt:         "created_at",
	UpdatedAt:         "updated_at",
	DeletedAt:         "deleted_at",
}

// NewUsersDao creates and returns a new DAO object for table data access.
func NewUsersDao() *UsersDao {
	return &UsersDao{
		group:   "default",
		table:   "users",
		columns: usersColumns,
	}
}

// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *UsersDao) DB() gdb.DB {
	return g.DB(dao.group)
}

// Table returns the table name of current dao.
func (dao *UsersDao) Table() string {
	return dao.table
}

// Columns returns all column names of current dao.
func (dao *UsersDao) Columns() UsersColumns {
	return dao.columns
}

// Group returns the configuration group name of database of current dao.
func (dao *UsersDao) Group() string {
	return dao.group
}

// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *UsersDao) Ctx(ctx context.Context) *gdb.Model {
	return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}

// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *UsersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
	return dao.Ctx(ctx).Transaction(ctx, f)
}
